<?php
    require "./autoload.php";

    use Qiniu\Auth;
    use Qiniu\Storage\UploadManager;
    header('content-Type: text/html; charset=utf-8');
    //ak、sk信息
    $accessKey = 'H9N6ZegIQ-cm2nIBHF9Gx4aBUK2dMUCj2zlgH4J6';
    $secretKey = 'uHzZsPd4Xds_hw1xaMixtOjOk2Ok_5iMtIZ7xJoA';
	
     
      $bucket = 'xinnuo1';
     //$file = "./xinnuo.mp4";
      	 	  	  
      // 初始化签权对象
      $auth = new Auth($accessKey, $secretKey);

      $policy=array(

	    'callbackUrl'=>'http://hu14.tophp.cn/callback.php',

		'callbackBody' => 'key=$(key)&hash=$(etag)&miaoshu=$(x:miaoshu)'

	  );
   		 
      //生成上传token
      $token = $auth->uploadToken($bucket,null,3600,$policy);
	 
      //$token = $auth->uploadToken($bucket);
		  
?>

<!DOCTYPE html>
<html>
<head>
	<title>测试表单上传</title>
	<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
</head>
<body>
	<form  id="uploadForm" method="post" action="" enctype="multipart/form-data">
	视频标题：
	<input name="key" type="text" value=""></br><br/>
	视频描述：
	<input name="x:miaoshu" type="text" value=""><br/><br/>
	
	<input name="token" type="hidden" value="<?php echo $token; ?>">
	<input name="file" type="file" />
	
	<input type="button" value="提交" onclick="doUpload()">
		
</form>
</body>
</html>

<script type="text/javascript">
	function doUpload() {  
     var formData = new FormData($( "#uploadForm" )[0]);  
     $.ajax({  
          url: 'http://upload.qiniu.com/' ,  
          type: 'POST',  
          data: formData,  
          async: false,  
          cache: false,  
          contentType: false,  
          processData: false,  
          success: function (returndata) { 
          	console.log(returndata);
          // var img_src ='<video controls="controls" src="http://oq4vbry69.bkt.clouddn.com/'+returndata.key+'"></video>';

            document.write('上传成功，文件路径是：http://oq4vbry69.bkt.clouddn.com/'+returndata.key+'文件描述：<br/>'+returndata.miaoshu);
          },  
          error: function (returndata) {  
              alert('上传出错，请修改文件名称，重新上传');  
          }  
     });  
}  


</script>


